package fudan.se.project.repository.entity.conference.post;


import fudan.se.project.domain.User;
import fudan.se.project.domain.conference.post.Rebuttal;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RebuttalRepository extends CrudRepository<Rebuttal, Long> {

    Rebuttal findById(long id);

    Rebuttal findByPostPaperId(long id);

    @Query("select distinct rebuttal from Rebuttal rebuttal " +
            "join rebuttal.post.paper paper " +
            "where paper.conference.id=:conferenceId " +
            "and paper.author.user=:user "
    )
    List<Rebuttal> findRebuttalsByConferenceIdAndAuthor(long conferenceId, User user);

    @Query(value = "select " +
            "distinct rebuttal " +
            "from Rebuttal rebuttal " +
            "join rebuttal.post.paper.reviewInfos reviewInfo " +
            "where rebuttal.post.paper.conference.id=:conferenceId " +
            "and reviewInfo.pcMember.user=:reviewer " +
            "and reviewInfo.version=:version "
    )
    List<Rebuttal> findRebuttalsByConferenceIdAndReviewerAndVersion(long conferenceId, User reviewer, int version);
}
